<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增菜房订单')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-ncOrderCf-add">

        <input value="1" name="cforderStatus" type="hidden">
        <input value="1" name="cforderFor" type="hidden">
        <input value="1" name="status" type="hidden">
        <!--作物品种ID-->
        <input id="treeId" name="cropVarieties" type="hidden" value="100"/>

        <div class="form-group">
            <label class="col-sm-3 control-label">订单类型：</label>
            <div class="col-sm-8">
                <select name="cforderType" required class="form-control m-b"
                        th:with="type=${@dict.getType('cforderType')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>

        <!--<div class="form-group">
            <label class="col-sm-3 control-label">作物名称：</label>
            <div class="col-sm-8">
                <input id="cropNameCn" name="cropNameCn" class="form-control" type="text">
            </div>
        </div>-->

        <div class="form-group">
            <label class="col-sm-3 control-label">作物品种：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" name="cropVarietiesCn" type="text" required onclick="selectCaiTree()"
                           id="treeName" readonly="true">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>

        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">需求数量：</label>
            <div class="col-sm-8">
                <input id="requestAmount" required name="requestAmount" class="form-control" type="number">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">单位：</label>
            <div class="col-sm-8">
                <select name="unit" required class="form-control m-b" th:with="type=${@dict.getType('normal_unit')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">需求时间：</label>
            <div class="col-sm-8">
                <input id="requestTime" data-format="yyyy-MM-dd" name="requestTime" required
                       th:value="*{#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd')}" class="form-control"
                       type="text" th:class="time-input">
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea rows="4" name="remark" class="form-control" type="text"></textarea>
            </div>
        </div>

    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "system/ncOrderCf"
    var cai_prefix = ctx + "system/cai";
    $("#form-ncOrderCf-add").validate({
        rules: {
            xxxx: {
                required: true,
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-ncOrderCf-add').serialize(),function () {
                /*  parent.reload();*/
                $.modal.closeLoading();
                $.modal.enable();
                $.modal.msgSuccess("添加成功！");
                parent.$('#bootstrap-table').bootstrapTable('refresh', {
                    silent: true
                });
            },1);

        }
    }

    /*蔬菜管理-新增-选择父蔬菜树*/
    function selectCaiTree() {
        var options = {
            title: '蔬菜选择',
            width: "380",
            url: cai_prefix + "/selectCaiTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }


    }

</script>
</body>
</html>
